package com.sunxd.vue.domain.bean.assembler;

import com.alibaba.fastjson.JSON;
import com.sunxd.vue.bean.request.UserReq;
import com.sunxd.vue.bean.request.UserUpdateReq;
import com.sunxd.vue.bean.response.UserVo;
import com.sunxd.vue.domain.bean.domain.User;
import com.sunxd.vue.infrastructure.adapter.db.po.UserPO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.ReportingPolicy;

import java.util.Date;
import java.util.Objects;

import static org.mapstruct.factory.Mappers.getMapper;

@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserAssembler {

    UserAssembler CONVERTER = getMapper(UserAssembler.class);

    /**
     * converter
     */
    @Named(value = "date2Long")
    default Long date2Long(Date date) {
        if (Objects.isNull(date)) {
            return null;
        }
        return date.getTime();
    }

    @Mappings({
            @Mapping(target = "timeMillions", source = "updateTime" ,qualifiedByName = "date2Long"),
    })
    UserVo do2vo(User request);

    User req2do(UserReq request);
    User upReq2do(UserUpdateReq request);





}
